package com.ushine.web.component.mybatis.desensitization.annotation;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author: yls
 * @Date: 2021/01/14 19:46
 * @Description: 脱敏序列化类
 * @Version 1.0
 */
@Slf4j
public class DesensitizationFormatter {
}

//public class DesensitizationFormatter extends JsonSerializer<String> implements
//        ContextualSerializer {
//
//    private SensitiveTypeEnum type;
//
//    @Resource
//    private DesensitizationServiceImpl desensitizationService;
//
//    /**
//     * 必须保留无参数构造方法
//     */
//    public DesensitizationFormatter() {
//
//    }
//
//    private DesensitizationFormatter(SensitiveTypeEnum type) {
//        this.type = type;
//    }
//
//    /**
//     * 序列化的过程中脱敏
//     *
//     * @param value              字段值
//     * @param jsonGenerator      json生成器
//     * @param serializerProvider 序列号提供器
//     * @throws IOException io 异常
//     */
//    @Override
//    public void serialize(String value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
//        switch (this.type) {
//            case CHINESE_NAME:
//                jsonGenerator.writeString(desensitizationService.hiddenChineseName(value));
//                break;
//            case ID_CARD:
//                jsonGenerator.writeString(desensitizationService.hiddenIdCard(value));
//                break;
//            case CAR_NUMBER:
//                jsonGenerator.writeString(desensitizationService.hiddenCarNumber(value));
//                break;
//            case FIXED_PHONE:
//                jsonGenerator.writeString(desensitizationService.hiddenFixedPhone(value));
//                break;
//            case MOBILE_PHONE:
//                jsonGenerator.writeString(desensitizationService.hiddenPhone(value));
//                break;
//            case ADDRESS:
//                jsonGenerator.writeString(desensitizationService.hiddenAddress(value));
//                break;
//            case EMAIL:
//                jsonGenerator.writeString(desensitizationService.hiddenEmail(value));
//                break;
//            case BANK_CARD:
//                jsonGenerator.writeString(desensitizationService.hiddenBankCard(value));
//                break;
//            default:
//        }
//
//    }
//
//    @Override
//    public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty property) throws JsonMappingException {
//        // 为空直接跳过
//        if (property != null) {
//            // 非 String 类直接跳过
//            if (Objects.equals(property.getType().getRawClass(), String.class)) {
//                Desensitization desensitization = property.getAnnotation(Desensitization.class);
//                if (desensitization == null) {
//                    desensitization = property.getContextAnnotation(Desensitization.class);
//                }
//                // 如果能得到注解，就将注解的 value 传入 SensitiveInfoSerialize
//                if (desensitization != null) {
//                    return new DesensitizationFormatter(desensitization.type());
//                }
//            }
//            return serializerProvider.findValueSerializer(property.getType(), property);
//        }
//        return serializerProvider.findNullValueSerializer(property);
//
//    }
//}
